var e, a = getApp();

Page({
    data: {
        defaultSize: "default",
        primarySize: "default",
        warnSize: "default",
        disabled: !1,
        plain: !1,
        loading: !1,
        order_id: "",
        done: {
            name: "付款金额",
            price: "7520.00"
        },
        doneList: [ {
            order_sn: "订单号"
        }, {
            order_sn: "配送方式"
        } ],
        flowMoney: {
            checkoutUrl: "../user/index"
        },
        user:{}
    },
    onLoad: function(t) {
        var token = wx.getStorageSync("token");
        var d = this;
        this.loadingChange();
        var i = t.id;
        wx.request({
            url: a.apiUrl("user/order/detail"),
            method: "post",
            data: {
                id: i
            },
            header: {
                "Content-Type": "application/json",
                "X-ECTouch-Authorization": token
            },
            success: function(e) {
                d.setData({
                    doneList: e.data.data,
                    donePrice: e.data.data,
                    order_id: e.data.data.order_id
                });


                wx.request({
                    url: a.apiUrl("user/info"),
                    data: {
                        per_page: "10",
                        page: "1",
                        list: ""
                    },
                    header: {
                        "Content-Type": "application/json",
                        "X-ECTouch-Authorization": token
                    },
                    method: "POST",
                    success: function(result) {
                        
                        setTimeout(()=>{

                            let show_more_pay =  false;
                            // console.log('-----------')
                            // console.log(d.data.donePrice.order_amount);
                            // console.log(result.data.data.userInfo.user_money)
                            if(parseFloat(d.data.donePrice.order_amount) > parseFloat(result.data.data.user_money)){
                                // console.log('ddddd')
                                show_more_pay = true;
                            }
                            
                            d.setData({
                                user:result.data.data,
                                wx_pay:( d.data.donePrice.order_amount - result.data.data.user_money).toFixed(2),
                                show_more_pay:show_more_pay
                            })

                        },500)
                         
        
                    }
                });
            }
        });
        
    },
    creditPay:function(e){
        var that = this, token = wx.getStorageSync("token");
     
               
        // var money = result.data.data.userInfo.user_money;
        
        wx.request({
            url: a.apiUrl("payment/credit_pay"),
            data: {
                order_sn: that.data.donePrice.order_sn,  
            },
            header: {
                "Content-Type": "application/json",
                "X-ECTouch-Authorization": token
            },
            method: "POST",
            success: function(result_pay) {
                wx.showModal({
                    title: '提示',
                    content: result_pay.data.data.msg,
                    showCancel:false,
                    success:function(){
                        if(result_pay.data.data.code == 200){
                            wx.switchTab({
                                url: "../user/index"
                            });
                        }
                    }
                })
            }
        });


                


    },
    
    loadingChange: function() {
        var e = this;
        setTimeout(function() {
            e.setData({
                hidden: !0
            });
        }, 2e3);
    },
    onPullDownRefresh: function() {
        wx.stopPullDownRefresh();
    },
    formSubmit: function(t) {
        console.log(t)
        var d = t.detail.formId, i = this.data.order_id, o = wx.getStorageSync("openid");
        var credit_money = t.detail.target.dataset.credit,wx_money = t.detail.target.dataset.wx
        a.payOrder(i, o, e, d,credit_money,wx_money);
    },
    orderDetail: function(e) {
        wx.switchTab({
            url: "../user/index"
        });
    }
});